package com.hot100;

import java.util.HashMap;
import java.util.Map;

public class Solution152 {
    public int maxProduct(int[] nums) {
        int res = nums[0];
        int curMin = nums[0];
        int curMax = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] < 0) {
                curMax = curMax ^ curMin;
                curMin = curMax ^ curMin;
                curMax = curMax ^ curMin;
            }
            curMax = Math.max(nums[i], curMax * nums[i]);
            curMin = Math.min(nums[i], curMin * nums[i]);
            res = Math.max(curMax, res);
        }
        return res;
    }
}
